#pragma GCC optimize(2)
#pragma GCC optimize(3)

#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
const int N = 1e6 + 2;
#define fi first
#define se second
#define pb push_back
#define wzh(x) cerr<<#x<<'='<<x<<endl;
int n, k;
LL a[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++)cin >> a[i];
    LL l = 1, r = 1e11, ans = 1;
    while (l <= r) {
        LL mid = l + r >> 1;
        int cost = 0;
        for (int i = 1, j; i <= n; i = j + 1) {
            if (a[i] > mid) {
                cost = k + 1;
                break;
            }
            j = i;
            LL res = a[i];

            while (j + 1 <= n && 0ll + res + a[j + 1] <= mid)j++, res += a[j];
            cost++;
        }
        if (cost <= k)ans = mid, r = mid - 1;
        else l = mid + 1;
    }
    cout << ans << '\n';
    return 0;
}
